package com.only4play.practice.asset.core.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.only4play.codegen.processor.api.*;
import com.only4play.codegen.processor.controller.GenController;
import com.only4play.codegen.processor.creator.GenCreator;
import com.only4play.codegen.processor.creator.IgnoreCreator;
import com.only4play.codegen.processor.dto.GenDto;
import com.only4play.codegen.processor.entitymapper.GenObjectMapper;
import com.only4play.codegen.processor.mapper.GenMapper;
import com.only4play.codegen.processor.query.GenQuery;
import com.only4play.codegen.processor.service.GenService;
import com.only4play.codegen.processor.service.GenServiceImpl;
import com.only4play.codegen.processor.updater.GenUpdater;
import com.only4play.codegen.processor.updater.IgnoreUpdater;
import com.only4play.codegen.processor.vo.GenVo;
import com.only4play.codegen.support.annotation.FieldDesc;
import com.only4play.codegen.support.constants.ValidStatus;
import com.only4play.codegen.support.model.BaseEntity;
import com.only4play.practice.common.enums.SkuType;
import lombok.Data;

import java.util.List;

@GenCreator(pkgName = "com.only4play.practice.asset.model.creator")
@GenUpdater(pkgName = "com.only4play.practice.asset.model.updater")
// findById方法
@GenVo(pkgName = "com.only4play.practice.asset.model.vo")
// findByPage方法
@GenQuery(pkgName = "com.only4play.practice.asset.model.query")
@GenCreateRequest(pkgName = "com.only4play.practice.asset.model.request")
@GenUpdateRequest(pkgName = "com.only4play.practice.asset.model.request")
@GenQueryRequest(pkgName = "com.only4play.practice.asset.model.request")
@GenResponse(pkgName = "com.only4play.practice.asset.model.response")
@GenDto(pkgName = "com.only4play.practice.asset.model.dto")

@GenFeign(pkgName = "com.only4play.practice.asset.model.feign")

// 生成serviceImpl
@GenObjectMapper(pkgName = "com.only4play.practice.asset.entitymapper")
// 生成serviceImpl
@GenMapper(pkgName = "com.only4play.practice.asset.core.mapper")
@GenService(pkgName = "com.only4play.practice.asset.core.service")
@GenServiceImpl(pkgName = "com.only4play.practice.asset.core.service.impl")

@GenController(pkgName = "com.only4play.practice.asset.core.controller")


@Data
public class ObjectSku extends BaseEntity {

  @FieldDesc(name = "sku名称")
  private String skuName;

  @FieldDesc(name = "模板ID")
  private Long templateId;

  @FieldDesc(name = "编码")
  private String code;

  @FieldDesc(name = "备注")
  private String remark;

  @FieldDesc(name = "sku类型")
  private SkuType skuType;

  /**
   * 用于开票归类，按照国家编码目录配置
   */
  @FieldDesc(name = "税务分类编码")
  private String taxCategoryNo;

  @FieldDesc(name = "计量单位")
  private String measureUnit;

  @FieldDesc(name = "子sku ID list")
  @TableField(typeHandler = JacksonTypeHandler.class)
  private List<Long> children;

  @FieldDesc(name = "是否需要序列号")
  private ValidStatus uniqueFlag;

  @IgnoreUpdater
  @IgnoreCreator
  private ValidStatus validStatus;

  public void init() {
    setValidStatus(ValidStatus.VALID);
    setUniqueFlag(ValidStatus.VALID);
  }

  public void valid(){
    setValidStatus(ValidStatus.VALID);
  }

  public void invalid(){
    setValidStatus(ValidStatus.INVALID);
  }
}
